<script lang="ts" setup>
import { ref } from 'vue'
import http from '@/http'
import { useI18n } from '@/hooks/web/useI18n'

import BoxView2 from '@/components/BoxView2.vue'
import BgVue4 from '@/components/BgVue4.vue'

const { t } = useI18n()
type ItemType = {
  address: string
  time: string
}
const list = ref<ItemType[]>([])
async function init() {
  const res = await http.get('/api/user/friends')
  if (res.code === 200) {
    // inviteAddress.value = res.data.inviteAddress
    // count.value = res.data.count
    list.value = res.data.list.map((row: any) => {
      return {
        address: row.address.substr(0, 20) + '...' + row.address.substr(38),
        time: row.create_time.substr(0, 16).replace('T', ''),
      }
    })

    if (process.env.NODE_ENV !== 'production') {
      list.value = [
        {
          address: 'xxx',
          time: '2020-2-2 00:00:00',
        },
        {
          address: 'xxx',
          time: '2020-2-2 00:00:00',
        },
      ]
    }
  }
}

init()
</script>
<template>
  <BgVue4 class="FriendsList">
    <div class="friend-box">
      <div class="title-style tit"> {{ t('Myfriend.friend') }} </div>
      <div class="list">
        <BoxView2 v-for="(item, index) in list" :key="index">
          <div class="item">
            <div class="l">
              <div class="no">{{ index + 1 }}</div>
            </div>
            <div class="m">
              <div class="label">{{ t('Myfriend.address') }}</div>
              <div class="val">{{ item.address }}</div>
            </div>
            <div class="r">
              <div class="label">{{ t('Myfriend.time') }}</div>
              <div class="val">{{ item.time }}</div>
            </div>
          </div>
        </BoxView2>
      </div>
    </div>
  </BgVue4>
</template>

<style lang="less" scoped>
.FriendsList {
  color: #fff;

  .friend-box {
    font-size: 12px;

    .tit {
      padding: 10px 0;
      font-size: 22px;
      text-align: center;
    }

    .item {
      display: flex;
      background-color: hsla(47, 90%, 48%, 0.08);
      border-radius: 10px;
      padding: 10px 0;
    }

    .item + .item {
      margin-top: 10px;
    }

    .l {
      display: flex;
      align-items: center;
      padding-left: 16px;
    }

    .m {
      flex: 1;
      padding: 0 10px;
    }

    .r {
      padding-right: 18px;
      text-align: right;
    }

    .no {
      width: 25px;
      height: 25px;
      // color: #ebb90c;
      line-height: 25px;
      text-align: center;
      // background-color: #5c4e1c;
      border-radius: 25px;
      border: 1px solid #94ddf4;
    }

    // .label {}

    .val {
      margin-top: 7px;
      word-break: break-all;
    }
  }
}
</style>
